<?php
include_once("../config/config.php");

require_once(DATA_PATH."table_dao.php");
require_once(CLASS_PATH."Api.php");
include_once(CLASS_PATH."Amazon.php");
include_once(CLASS_PATH."logic.php");

////////////////////////////////////////////////////////////
if(_GET("type")=="history"){
	$get_store = _GET("store");
  $Data_history = array(
		"Id"	=>	_GET("id"),
		"site"	=>	_GET("site"),
		"sType"	=>	_GET("sType"),
		"title"	=>	_GET("title"),
		"itemid"	=>	_GET("itemid"),
		"img"	=>	_GET("img"),
		"price"	=>	_GET("price"),
		"store"	=>	empty($get_store)?" ":$get_store,
		"endtime"	=>	_GET("endtime"),
		"itemkey"	=>	_GET("itemkey"),
		);
  $Data_shistory = array(
		"Id"	=>	_GET("id"),
		"site"	=>	_GET("site"),
		"itemid"	=>	_GET("itemid"),
		);
		
    if($Data_history["site"]=="amazon"&&($Data_history["price"]==0||$Data_history["price"]==null)){
        $amazon = new Amazon();
        $Data_history["price"] = $amazon->GetPriceByItemid($Data_history["itemid"]);
    }

  $history_dao = new table_dao("history");
  $result = $history_dao->get($Data_history);
  if(empty($result)){
    $history_dao->add($Data_history);
  }
  //echo $history_dao->insertid;
}else if(_GET("type")=="gethistory"){
  $Data_history = array(
		"Id"	=>	_GET("id"),
		"site"	=>	_GET("site"),
		"itemid"	=>	_GET("itemid"),
		"orderby" => "`Id` DESC"
		);
  $history_dao = new table_dao("history");
  $result = $history_dao->get($Data_history);
  $api = new Api();
  print_r($api->Set($result,_GET("dom")));
}else if(_GET("type")=="getprice"){
  $test = new Amazon();
  print_r($test->GetPrice(_GET("url")));
}else{
  $test = new logic($_GET);
  print_r($test->Output(_GET("op"),_GET("dom")));
}
/*
$data = array(
		"site"=>_GET("site"),
		"type"=>_GET("type")
		);
$test = new logic($data);
print_r($test->Output("list",_GET("dom")));//need keyword (q)
print_r($test->Output("item",_GET("dom")));//need itemid
print_r($test->Output("category",_GET("dom")));
print_r($test->Output("sortorder",_GET("dom")));
print_r($test->Output("interface",_GET("dom")));
*/


?>